package com.longge;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-06-02 22:12
 */
public class RightSideView {
    int dep = 0;
    List<Integer> arr = new ArrayList<>();
    public List<Integer> rightSideView(TreeNode root) {

        dfs(root,1);
        return arr;
    }

    private void dfs(TreeNode root, int i) {
        if (root==null) return;
        if (dep<i) {
            dep=i;
            arr.add(root.val);
        }
        dfs(root.right,i+1);
        dfs(root.left,i+1);
    }

}
